package com.wjc.myktapplication.page.project

import android.content.Intent
import android.view.View
import com.idlefish.flutterboost.containers.FlutterBoostActivity
import com.wjc.basemodule.base.BaseFragment
import com.wjc.basemodule.base.DataBindingConfig
import com.wjc.basemodule.utils.LogTools
import com.wjc.myktapplication.BR
import com.wjc.myktapplication.R
import com.wjc.myktapplication.databinding.FragmentProjectMainBinding
import io.flutter.embedding.android.FlutterActivityLaunchConfigs

/**
 * 项目主页
 */

class ProjectMainFragment : BaseFragment<FragmentProjectMainBinding>(), View.OnClickListener {
    val TAG = "ProjectMainFragment"
    override val dataBindingConfig: DataBindingConfig
        get() = DataBindingConfig(R.layout.fragment_project_main).addBindingParam(BR.click, this)


    inner class ClickProxy {
        fun clickImageFragment() {
            nav().navigate(R.id.action_mainHomeFragment_to_imageViewFragment)
        }

        fun clickDragView() {
            nav().navigate(R.id.action_mainHomeFragment_to_dragViewFragment)
        }

        fun clickTagLayout() {
            nav().navigate(R.id.action_mainHomeFragment_to_tagLayoutFragment)
        }

        fun clickProgress() {
            nav().navigate(R.id.action_mainHomeFragment_to_progressWidgetFragment)
        }

        fun clickUpdateThread() {
            LogTools.d(TAG, ": clickUpdateThread");
            Thread {
                LogTools.d(TAG, ": clickUpdateThread 22");
                binding.tvProUpdateThread.text = "clickUpdateThread"
            }.start()

        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_pro_drag -> {
                val params: MutableMap<String, Any> = HashMap()
                params["string"] = "a string"
                params["bool"] = true
                params["int"] = 666
                val intent = FlutterBoostActivity.CachedEngineIntentBuilder(FlutterBoostActivity::class.java)
                    .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.opaque)
                    .destroyEngineWithActivity(false)
                    .url("mainPage")
                    .urlParams(params)
                    .build(activity)
                startActivityForResult(intent, 200)
            }
            R.id.tv_pro_tag_layout -> {
                val params: MutableMap<String, Any> = HashMap()
                params["string"] = "a string"
                params["bool"] = true
                params["int"] = 666
                val intent = FlutterBoostActivity.CachedEngineIntentBuilder(FlutterBoostActivity::class.java)
                    .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.opaque)
                    .destroyEngineWithActivity(false)
                    .url("settingPage")
                    .urlParams(params)
                    .build(activity)
                startActivityForResult(intent, 200)
            }
        }

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        LogTools.d(TAG, ": resultCode=$resultCode");
    }
}